﻿using System;
using fastCSharp;

namespace diantou.web.onlineJudge
{
    /// <summary>
    /// 问题列表
    /// </summary>
    /// <typeparam name="viewType"></typeparam>
    abstract class problemList<viewType> : view<viewType>
        where viewType : problemList<viewType>
    {
        /// <summary>
        /// 问题分组
        /// </summary>
        protected diantou.dataAccess.problemGroup.userProblemGroup group;
        /// <summary>
        /// 问题列表
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected userProblem[] problems;
        /// <summary>
        /// 分组菜单
        /// </summary>
        protected groupMenu groupMenu
        {
            get { return new groupMenu { ViewOnly = requestHeader.IsReView }; }
        }
        /// <summary>
        /// 是否现实分值排序
        /// </summary>
        protected virtual bool isPointSort
        {
            get { return true; }
        }
        /// <summary>
        /// 清除数据
        /// </summary>
        protected override void clear()
        {
            base.clear();
            group.Group = null;
        }
    }
    /// <summary>
    /// 问题列表
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class problemList : problemList<problemList>
    {
        /// <summary>
        /// 是否现实分值排序
        /// </summary>
        protected override bool isPointSort
        {
            get { return group.Group.Id == diantou.dataAccess.problemGroup.AllGroup.Id; }
        }
        /// <summary>
        /// 初始化问题列表
        /// </summary>
        /// <param name="groupId">分组标识</param>
        /// <param name="page">分页号</param>
        /// <param name="sort">排序类型</param>
        /// <param name="isAsc">是否升序</param>
        /// <returns>是否成功</returns>
        private bool loadView(int groupId, int page, diantou.dataAccess.problem.sort sort, bool isAsc)
        {
            diantou.dataAccess.problemGroup problemGroup = null;
            if (groupId > 0) problemGroup = diantou.dataAccess.clientCache.ProblemGroup[groupId];
            if (problemGroup == null)
            {
                problemGroup = diantou.dataAccess.problemGroup.AllGroup;
                //query.groupId = -1;
            }
            group = new dataAccess.problemGroup.userProblemGroup { Group = problemGroup, UserId = currentUserId };
            diantou.dataAccess.problem[] problems = diantou.dataAccess.clientCache.Problem.Get(diantou.dataAccess.tcpCall.problem.getIds(group.Group.Id, sort, isAsc, pageInfo.Size = 20, pageInfo.Page = page, currentUserId, currentUser != null && currentUser.IsChangeVisit, out pageInfo.Count));
            this.problems = problems.getArray(value => new userProblem { Problem = value, User = currentUser });
            if (requestHeader.IsSearchEngine) pageInfo.Path = problemGroup.Path.List.ToPageString();
            return true;
        }
    }
}
